<template>
  <div class="ArticleBlog">
    <!--图片标题-->
    <div class="pattern-center single-center">
      <div class="pattern-attachment-img">
        <el-image fit="cover" lazy :src="articleInfo.titlePicture">
          <template #error>
            <div class="image-slot">
              <el-image
                :src="randomArrayIndex(store.state.defaultErrorImageUrl)"
                fit="cover"
              ></el-image>
            </div>
          </template>
        </el-image>
      </div>
      <transition-group
        enter-active-class="animate__animated animate__zoomIn"
        leave-active-class="animate__animated animate__backOutDown"
      >
      </transition-group>
      <transition
        enter-active-class="animate__animated animate__backInDown"
        leave-active-class="animate__animated animate__backOutDown"
      >
        <div class="single-header">
          <h1 class="entry-title">标签</h1>
        </div>
      </transition>
    </div>
    <div id="content" class="site-content">
      <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
          <div class="entry-content">
            <!--内容-->
            <div class="links">
              <ul class="link-items fontSmooth">
                <li
                  class="link-item"
                  v-for="(item, index) in tagData"
                  :key="index"
                  @click="checkTag(item)"
                >
                  <p
                    class="link-item-inner effect-apollo"
                    :title="item.tagName"
                    target="_blank"
                    rel="friend"
                  >
                    <img
                      class="lazyload tagImg"
                      :data-src="item.tagPicture"
                      :src="item.tagPicture"
                    />
                    <span class="sitename"> {{ item.tagName }} </span>
                    <span class="linkdes"> {{ item.tagNote }} </span>
                  </p>
                </li>
              </ul>
            </div>
            <article
              class="post post-list"
              v-for="(item, index) in articleData"
              :key="index"
            >
              <router-link
                :to="{ path: `/article/${item.id}` }"
                class="button-normal"
              >
                <div class="post-entry">
                  <div class="feature">
                    <div class="overlay">
                      <i class="iconfont icon-text" />
                    </div>
                    <img
                      width="150"
                      height="150"
                      :src="item.titlePicture"
                      class="attachment-post-thumbnail size-post-thumbnail wp-post-image tag-list-img"
                      alt=""
                      loading="lazy"
                    />
                  </div>
                  <h1 class="entry-title">
                    {{ item.title }}
                  </h1>
                  <div class="p-time">
                    <i class="fa fa-clock-o" aria-hidden="true" />
                    发布于 {{ item.createTime }}
                  </div>
                  <p> {{ item.context }} </p>
                  <footer class="entry-footer">
                    <div class="post-more">
                      <i class="iconfont icon-caidan"></i>
                    </div>
                    <div class="info-meta">
                      <div class="comnum">
                        <span>
                          <i
                            class="fa fa-commenting-o animated faa-ring faa-slow"
                            aria-hidden="true"
                          />
                          <a href="#">{{ item.commentDistCount }} 条评论</a>
                        </span>
                      </div>
                      <div class="views">
                        <span>
                          <i
                            class="fa fa-fire animated faa-vertical faa-slow"
                            aria-hidden="true"
                          />{{ item.views }} 热度
                        </span>
                      </div>
                    </div>
                  </footer>
                </div>
              </router-link>
            </article>
          </div>
        </main>
      </div>
    </div>
  </div>
  <!--分享区,版权区-->
  <div
    class="three_consecutive_operations"
    @click="headerTopDown('#comment-anchor')"
  >
  </div>
</template>

<script setup>
  import { onBeforeMount, reactive, onMounted, toRaw, ref } from 'vue'
  import { randomArrayIndex } from '@/utils/randomArrayElemt.js'
  import { useStore } from 'vuex'
  import { getRecommend } from '@/api/article/article.js'
  import { headerTopDown } from '@/utils/webutils'
  import { getTagList } from '@/api/tag/tag'
  import { listByQuery } from '@/api/article/article'

  const store = new useStore()

  // 文章信息
  const articleInfo = reactive({
    titlePicture: ''
  })

  //推荐文章信息
  const recommendArticleInfo = reactive({
    pre: {},
    next: {}
  })

  const tagData = toRaw(ref([]))
  const articleData = toRaw(ref([]))

  /**
   * 获取推荐文章
   * @param id
   */
  const getRecommendList = () => {
    getRecommend({})
      .then((res) => {
        recommendArticleInfo.next = res.data.next
        recommendArticleInfo.pre = res.data.pre
      })
      .catch(() => {})
  }

  /**
   * 获取标签列表
   */
  const tagListFunc = () => {
    getTagList()
      .then((res) => {
        tagData.value.push(...res.data.records)
      })
      .catch(() => {})
  }

  /**
   * 点击标签获取文章列表
   * @param tag
   */
  const checkTag = (tag) => {
    articleData.value = []
    let params = {
      articleTag: tag.id
    }
    listByQuery(params)
      .then((res) => {
        articleData.value.push(...res.data.records)
      })
      .catch(() => {})
  }

  onBeforeMount(() => {})

  onMounted(() => {
    getRecommendList()
    tagListFunc()
  })
</script>

<style lang="less" scoped>
  .tag-list-img {
    margin-left: 20px;
    margin-top: 5px;
    border: 0;
    width: 140px;
    height: 70px;
    border-radius: 5%;
  }

  .tagImg {
    transform: scale(0.9);
    -webkit-transform: scale(0.9);
    -moz-transform: scale(0.9);
    -o-transform: scale(0.9);
    -ms-transform: scale(0.9);
    transition: all ease 1s;
    -webkit-transition: all ease 1s;
    -moz-transition: all ease 1s;
    -o-transition: all ease 1s;
    width: 140px;
    height: 70px;
    border-radius: 10%;
    padding: 1px;
  }

  .post-nav {
    margin: 25px 0;
    height: 150px;
    display: flex;
    background-color: #000000;
    justify-content: space-between;
    border-radius: 10px 10px 0 0;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);

    :deep(.el-image) img {
      opacity: 0.4;
      background-size: cover;
      -webkit-transition: opacity 0.15s ease-out;
      -moz-transition: opacity 0.15s ease-out;
      transition: opacity 0.15s ease-out;
      border-radius: 10px 10px 0 0;
    }

    .left-pre:hover > :deep(.el-image) img,
    .right-next:hover > :deep(.el-image) img {
      opacity: 0.7;
    }

    div {
      overflow: hidden;
      flex: 1;
    }

    .left-pre {
      position: relative;

      .blog-label {
        position: absolute;
        top: 50px;
        left: 35px;
        text-align: left;
      }
    }

    .right-next {
      position: relative;

      .blog-label {
        position: absolute;
        top: 50px;
        right: 60px;
        text-align: right;
      }
    }

    .blog-label {
      span,
      .info h3 {
        font-size: 14px;
        font-weight: 400;
        line-height: 30px;
        color: #fff;
        text-transform: uppercase;
        color: rgba(255, 255, 255, 0.7);
      }
    }

    span,
    h3 {
      overflow: hidden !important;
      text-overflow: ellipsis !important;
      display: -webkit-box !important;
      -webkit-box-orient: vertical !important;
      word-break: break-all !important; /*追加这一行代码*/
    }
  }

  .comment-form {
    .comment-user-avatar {
      display: flex;
      align-items: center;
      justify-content: center;

      .el-avatar {
        display: inline-block;
      }

      i {
        position: relative;
        right: 15px;
        bottom: 3px;
        color: #3cb45e;
        border-radius: 40%;
      }
    }

    .user-comment-Info {
      display: flex;
      flex-direction: column;

      .el-form-item--default .el-form-item__label {
        line-height: 42px;
      }
    }
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;
  }

  i {
    font-size: 20px;
  }

  .post-tags {
    i {
      font-size: 16px;
    }
  }

  .pattern-attachment-img {
    .el-image {
      width: 100%;
      height: 100%;
    }

    .image-slot {
      width: 100%;
      height: 100%;
    }
  }

  .single-center {
    .single-header {
      max-width: 860px;
      padding: 0 10px;
      margin-left: auto;
      margin-right: auto;
      margin-bottom: 60px;
      text-align: left;
      top: auto;
      bottom: 0;
      position: absolute;
      left: 0;
      right: 0;
      color: #fff;
      text-shadow: 2px 2px 10px #000;
      z-index: 1;

      .entry-census {
        .name {
          margin-left: 0.5rem;
        }

        .bull {
          margin: 0 0.5rem;
        }
      }
    }
  }

  .comment-textarea {
    :deep(.el-form-item__error) {
      top: 80%;
    }
  }

  .single-center .single-header {
    margin-bottom: 50px;
  }

  @media (max-width: 860px) {
    .single-center {
      .single-header {
        margin-bottom: 0;

        :deep(.el-col-22) {
          padding: 0 0 0 20px;
        }
      }
    }

    :deep(.notice) {
      font-size: 16px;
    }

    .post-nav {
      height: 100px;

      .left-pre .blog-label {
        top: 10px;
        left: 10px;
      }

      .right-next .blog-label {
        top: 10px;
        right: 10px;
      }
    }

    .single-center .entry-census {
      margin-bottom: 50px;

      p span {
        display: inline-block;
      }
    }
  }

  .three_consecutive_operations {
    position: fixed;
    display: flex;
    justify-content: center;
    align-items: center;
    bottom: 10vh;
    left: 35px;
    z-index: 100;

    .operations {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 55px;
      height: 55px;
      background-color: var(--global-bg);
      box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.2);
      transition: all 0.6s;
      cursor: pointer;
      border-radius: 50%;
      flex-direction: column;
      color: var(--font-color);

      div {
        margin: 2px 0;
      }
    }
  }

  .author-profile {
    .el-avatar--default {
      --el-avatar-size: px;
    }
  }

  .comment-user-avatar {
    .el-avatar--default {
      --el-avatar-size: 50px;
    }
  }

  .author {
    a {
      text-decoration: none;
    }
  }

  :deep(.el-input__inner) {
    border: none;
    background: var(--tab-botton-bg);
    color: var(--font-color);
    margin-bottom: 0;
  }

  :deep(.el-input__inner:focus) {
    color: var(--text-accent);
    box-shadow: 0 0 0 1px var(--text-accent) inset;
    background-color: var(--input-bg);
  }

  :deep(.el-input-group__prepend) {
    border: none;
    background: var(--tab-botton-bg);
    color: var(--font-color);
  }

  :deep(.el-textarea__inner:focus) {
    color: var(--text-accent);
    box-shadow: 0 0 0 1px var(--text-accent) inset;
    background-color: var(--input-bg);
  }

  :deep(.el-textarea__inner) {
    background-color: var(--tab-botton-bg);
  }

  .submit-comment {
    display: flex;
    justify-content: center;

    button {
      margin: 10px 30px;
    }
  }
</style>
